CFLAGS = -std=c99 -Wall
CC = gcc

# executable name
NAME = game

# sources
SRCS = main.c logger.c				       				\

# objects
OBJDIR = obj
OBJS := $(SRCS:.c=.o)
OBJS := $(addprefix $(OBJDIR)/, $(OBJS))

ifdef OS
	NAME := $(addsuffix .exe,$(NAME))
	LIBS = -lalleg
else
	LIBS = -L/usr/lib -lm -lpthread -lXxf86vm -lXcursor -lXpm -lXext -lX11 -ldl -lldpng -lpng -lz -lalleg
endif

# need output dir and the executable
all : $(OBJDIR) $(NAME)

# output dir
$(OBJDIR):
	mkdir $(OBJDIR)
	
# link the executable
$(NAME): $(OBJS)	# depends on object files
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
	@echo $(NAME) "successful compiled\n"

$(OBJDIR)/%.o: %.c
	@echo "[GCC] "$<
	$(CC) $(CFLAGS) -c $< -o $@
	
clean:
	@echo "Removing "$(OBJDIR)" and "$(NAME)
	rm -f -r $(OBJDIR)
	rm -f $(NAME)
	
